package com.forum.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.forum.pojo.StudentInfo;
import com.forum.pojo.vo.SearchStudentVo;
import com.forum.pojo.vo.StudentVo;
import com.forum.result.Result;
import com.forum.service.StudentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/studentInfo")
public class StudentInfoController {
    @Autowired
    StudentInfoService studentInfoService;
    @PostMapping("/getStudentsBySelector")
    public Result<Page> getStudents(@RequestBody SearchStudentVo searchStudentVo, @RequestParam  Long currentPage, @RequestParam Long limit){
            return studentInfoService.getStudentsBySelector(searchStudentVo,currentPage,limit);
    }
    @PutMapping("/updateIsAdmin")
    public Result updateIsAdmin(@RequestParam Long studentId,@RequestParam Integer isAdmin){
          int result=studentInfoService.updateIsAdmin(studentId,isAdmin);
          if(result==0){
              return Result.build(321,"修改失败");
          }else{
              return Result.ok();
          }
    }
    @ApiOperation("禁言学生")
    @PutMapping("/updateIsForbidden")
    public Result updateIsForbidden(@RequestParam Long studentId,@RequestParam Integer isForbidden){
        int result=studentInfoService.updateIsForbidden(studentId,isForbidden);
        if(result==0){
            return Result.build(321,"修改失败");
        }else{
            return Result.ok();
        }
    }
    @PostMapping("/insertStudent")
    public Result insertStudent(@RequestBody StudentVo studentVo){
        int result=studentInfoService.insertStudent(studentVo);
        if(result==0){
            return Result.build(322,"新增失败");
        }else{
            return Result.ok();
        }
    }
}
